<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
/***
* @author     Dennis T. Kaplan
* @copyright  Copyright (c) 2007, Dennis T. Kaplan
* @link       http://code.google.com/p/tamer/
* @created    01/01/2007
* @since      05/15/2007
* @version    1.2
* @license    GPL
* @package    CodeIgniter
* @subpackage Menu
* @filesource
***/

/*************************************************************************
*                                                                       *
* Copyright (c) 2007 Dennis T. Kaplan                                   *
* All rights reserved.                                                  *
*                                                                       *
* This script is free software; you can redistribute it and/or modify   *
* it under the terms of the GNU General Public License as published by  *
* the Free Software Foundation;                                         *
*                                                                       *
* The GNU General Public License can be found at                        *
* http://www.gnu.org/copyleft/gpl.html.                                 *
*                                                                       *
* This script is distributed in the hope that it will be useful,        *
* but WITHOUT ANY WARRANTY; without even the implied warranty of        *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the          *
* GNU General Public License for more details.                          *
*                                                                       *
************************************************************************/

class Menu
{
	function setVars()
	{
		$this->menu = array(
			'1' => anchor('', 'Welcome'),
            //Add new applications here
            '99' => anchor('testsuite', 'Help')
			);
        
        $this->sub['testsuite'] = array(
            anchor('testsuite/vars','Variables')
            );

/*#*****************************************************************************\
                    END OF USER CONFIG                                                
/*#*****************************************************************************/
        
        if($this->uid == 1){

            $this->menu['100'] = anchor('admin/', 'Admin');

            $this->sub['admin'] = array(
                anchor('admin/dbtamer','DB Tamer'),
                anchor('admin/data','Nested Data'),
                anchor('admin/pages','DB Pages'),
                anchor('admin/pages/add_edit_page','DB Page Add'),
                );
		}

	}
	
	function __construct()
	{
        $this->uid = 1;
		log_message('debug', 'Menu: initialized');
	}
	
	function mkMenu()
	{
		$CI =& get_instance();
		$this->setVars();
		ksort($this->menu);
		$segment = $CI->uri->segment(1);
        $menutmp = $this->menu;
		foreach($this->menu as $k => $v){
            $v = str_ireplace ($segment.'.php', '', $v); //I have no idea why I need this but without it it will not work for testsuite
			if (strripos($v, $segment) !== FALSE && isset($this->sub[$segment])){
				$this->menu[$this->menu[$k]] = $this->sub[$segment];
				unset($menutmp[$k]);
				$menutmp[$this->menu[$k]] = $this->sub[$segment];
			}
		}
		return $menutmp;
	}
}
?>
